package com.situ.staff.project.service.Impl;

import java.sql.SQLException;
import java.util.List;

import com.situ.staff.project.dao.ProjectDao;
import com.situ.staff.project.model.ProjectModel;
import com.situ.staff.project.service.IProjectService;

public class ProjectServiceImpl implements IProjectService {
	ProjectDao dao = new ProjectDao();

	@Override
	public String insert(ProjectModel model) throws SQLException {
		ProjectModel m0 = new ProjectModel();
		m0.setCode(model.getCode());
		ProjectModel m1 = dao.selectModel(m0);
		if (m1 == null) {
			return dao.insert(model) + "";
		} else {
			return "repeat";
		}
	}

	@Override
	public String delete(ProjectModel model) throws SQLException {

		return dao.delete(model) + "";
	}

	@Override
	public String update(ProjectModel model) throws SQLException {

		return dao.updateActive(model)+"";
	}

	@Override
	public List<ProjectModel> selectList(ProjectModel model) throws SQLException {
		String code = model.getCode();
		model.setCode(code == null ? "%%" : "%" + code + "%");
		String name = model.getName();
		model.setName(name == null ? "%%" : "%" + name + "%");

		return dao.selectList(model);
	}

	@Override
	public ProjectModel selectModel(ProjectModel model) throws SQLException {
		
		return dao.selectModel(model);
	}

	@Override
	public Integer selectCount(ProjectModel model) throws SQLException {
		ProjectModel m0 = new ProjectModel();
		String code = model.getCode();
		m0.setCode(code == null ? "%%" : "%" + code + "%");
		String name = model.getName();
		m0.setName(name == null ? "%%" : "%" + name + "%");

		return dao.selectCount(m0);
	}

}
